package com.vue.vuedemo.util;

import java.util.List;
import java.util.Objects;

import org.springframework.beans.BeanUtils;
/**
 * 使用spring beanUtils 定义一个复制 list bean的工具
 * @author zkr
 *
 * @param <T>
 */
// 依赖于 spring BeanUtils
public class ListUtils<T> {
    public void copyList(Object source, List<T> target, Class<T> classObj) {
        if ((!Objects.isNull(source)) && (!Objects.isNull(target))) {
            List list1 = (List) source;
            for (Object object : list1) {
            	T data=null;
				try {
					data = classObj.newInstance();
				} catch (InstantiationException e) {
					e.printStackTrace();
				} catch (IllegalAccessException e) {
					e.printStackTrace();
				}
            	BeanUtils.copyProperties(object, data);
            	target.add(data);
			}
        }
    }
}
